home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 910 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  56 lines

  1. Path: cs.mu.OZ.AU!bounce-back
  2. From: boukanov@hadron.fi.uib.no (Igor Boukanov)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Placement delete suggestion
  5. Date: 30 Mar 96 05:29:24 GMT
  6. Organization: Fysisk institutt, Universitetet i Bergen
  7. Approved: fjh@cs.mu.oz.au
  8. Message-ID: <4jgeld$e3s@ugress.uib.no>
  9. References: <4j4ec5$d41@fsgi01.fnal.gov> <9603261124.AA22276@lts.sel.alcatel.de> <4jboij$4t3@mulga.cs.mu.OZ.AU> <4jc296$h0t@news.BelWue.DE>
  10. NNTP-Posting-Host: munta.cs.mu.oz.au
  11. Keywords: delete placement
  12. X-Original-Date: 29 Mar 1996 10:39:41 GMT
  13. X-Newsreader: TIN [version 1.2 PL2]
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBFAgUBMVzG4eEDnX0m9pzZAQE7ZAF9GZMajuB8MX+r9l6lnmWrGbwckHW8HTSZ
  16.     D+QHn3msW85G10b0at4hN0GJhlMjBj7i
  17.     =fxMl
  18. Originator: fjh@munta.cs.mu.OZ.AU
  19.  
  20. Dietmar Kuehl (kuehl@uzwil.informatik.uni-konstanz.de) wrote:
  21.  
  22. > OTOH, as Tim Hollebeek observed in a thread in comp.lang.c++.moderated
  23. > (Placement new and arrays), the usefulness of placement array new is
  24. > limited anyway: There is no portable way to figure out how much
  25. > "allocation overhead" there will be and thus it is impossible to
  26. > predict how much memory has to be set aside for a placement array new.
  27.  
  28. But there is a way to way to figure out how much is "allocation overhead"!
  29. Here an example:
  30.  
  31. void* operator new[](size_t size, size_t& retSize) {
  32.    retSize = size;
  33.    return NULL;
  34. }
  35.  
  36. So you can call write something like this:
  37.  
  38. class T { ... };
  39. ...
  40. size_t size;
  41. new(size) T[100];
  42. T* p = new(alloca(size)) T[100]; // allocate memory from stack
  43. ...
  44. for (int i = 99; i >= 0; i--) { p[i].~T(); } 
  45.   // instead of placement delete ...
  46.  
  47. --
  48. With best regards, Igor Boukanov 
  49. igor.boukanov@fi.uib.no  http://www.fi.uib.no/~boukanov
  50. ---
  51. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  52. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  53. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  54. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  55. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  56.